package com.systemdevelopment.mainproject.View.Visitor;

import com.systemdevelopment.mainproject.Model.Author;
import com.systemdevelopment.mainproject.Model.Book;
import com.systemdevelopment.mainproject.View.PaneFactory;
import com.systemdevelopment.mainproject.View.mainUI;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;

import java.io.IOException;
import java.util.HashSet;

public class bookPane {
    private Pane linkPane;
    Pane getPane()
    {
        return linkPane;
    }
    bookPane(Book book)
    {
        FXMLLoader fxmlLoader = new FXMLLoader(bookPane.class.getResource("bookPreviewPane.fxml"));
        try {
            linkPane= fxmlLoader.load();
            ImageView coverImg= (ImageView) linkPane.lookup("#sketch");//后续需要补充加载代码
            coverImg.setImage(book.getImage());
            Hyperlink gotoBookPage= (Hyperlink) linkPane.lookup("#name");
            gotoBookPage.setText(book.getName());
            gotoBookPage.setOnMouseClicked((event -> {
                mainUI.CurBook=book;
                mainUI.loadBookContentPane();

            }));//跳转书籍详情页面
            Label author=(Label) linkPane.lookup("#author");
            HashSet<Author> cur_au=book.getAuthor();
            for(Author author1:cur_au)
            {
                author.setText(author1.getName());
                break;
            }



        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    bookPane()
    {
        FXMLLoader fxmlLoader = new FXMLLoader(bookPane.class.getResource("bookPreviewPane.fxml"));
        try {
            linkPane= fxmlLoader.load();
            //ImageView coverImg= (ImageView) linkPane.lookup("#coverImg");//后续需要补充加载代码
            //Hyperlink gotoBookPage= (Hyperlink) linkPane.lookup("#gotoBookPage");
            //gotoBookPage.setOnMouseClicked((event -> {}));//跳转书籍详情页面

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
